package com.ly.erms.config.properties;

import java.io.File;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import static com.ly.erms.core.util.ToolUtil.isEmpty;
import static com.ly.erms.core.util.ToolUtil.getTempPath;;

/**
 * Erms项目配置
 * 
 * @author liuyang
 * @date 2017年12月26日
 */
@Component
@ConfigurationProperties(prefix = ErmsProperties.PREFIX)
public class ErmsProperties {

	public static final String PREFIX = "erms";
	private Boolean kaptchaOpen = false;
	private String fileUploadPath;                    //头像路径
	private String publicFilePath;					  //公共文件库上传路径
	private Boolean haveCreatePath = false;
	private Boolean springSessionOpen = false;
	private Integer sessionInvalidateTime = 30 * 60; // session 失效时间
														// （默认30分钟，单位：秒）
	private Integer sessionvalidationInterval = 15 * 60; // session
															// 验证失效时间（默认15分钟，单位：秒）
	private Boolean mutiDatasourceOpen = false; // 是否开启多数据源
	private Boolean swaggerOpen = false;

	public String getFileUploadPath() {
			// 判断有没有结尾符，没有得加上
			if (!fileUploadPath.endsWith(File.separator)) {
				fileUploadPath = fileUploadPath + File.separator;
			}
			// 判断目录是否存在，没有得加上
			if (!haveCreatePath) {
				File file = new File(fileUploadPath);
				file.mkdirs();
				haveCreatePath = true;
			}
			return fileUploadPath;
	}

	public Boolean getMutiDatasourceOpen() {
		return mutiDatasourceOpen;
	}

	public void setMutiDatasourceOpen(Boolean mutiDatasourceOpen) {
		this.mutiDatasourceOpen = mutiDatasourceOpen;
	}

	public Boolean getSpringSessionOpen() {
		return springSessionOpen;
	}

	public void setSpringSessionOpen(Boolean springSessionOpen) {
		this.springSessionOpen = springSessionOpen;
	}

	public Boolean getKaptchaOpen() {
		return kaptchaOpen;
	}

	public void setKaptchaOpen(Boolean kaptchaOpen) {
		this.kaptchaOpen = kaptchaOpen;
	}

	public void setFileUploadPath(String fileUploadPath) {
		this.fileUploadPath = fileUploadPath;
	}

	public Boolean getHaveCreatePath() {
		return haveCreatePath;
	}

	public void setHaveCreatePath(Boolean haveCreatePath) {
		this.haveCreatePath = haveCreatePath;
	}

	public Integer getSessionInvalidateTime() {
		return sessionInvalidateTime;
	}

	public void setSessionInvalidateTime(Integer sessionInvalidateTime) {
		this.sessionInvalidateTime = sessionInvalidateTime;
	}

	public Integer getSessionvalidationInterval() {
		return sessionvalidationInterval;
	}

	public void setSessionvalidationInterval(Integer sessionvalidationInterval) {
		this.sessionvalidationInterval = sessionvalidationInterval;
	}

	public Boolean getSwaggerOpen() {
		return swaggerOpen;
	}

	public void setSwaggerOpen(Boolean swaggerOpen) {
		this.swaggerOpen = swaggerOpen;
	}

	public String getPublicFilePath() {
		// 判断有没有结尾符，没有得加上
		if (!publicFilePath.endsWith(File.separator)) {
			publicFilePath = publicFilePath + File.separator;
		}
		// 判断目录是否存在，没有得加上
		if (!haveCreatePath) {
			File file = new File(publicFilePath);
			file.mkdirs();
			haveCreatePath = true;
		}
		return publicFilePath;
	}

	public void setPublicFilePath(String publicFilePath) {
		this.publicFilePath = publicFilePath;
	}
}
